/**
 * 
 */
package org.tigris.apexam.configuration.implementation;

import java.io.*;
import java.util.*;

import org.tigris.elfin.ExpressionProcessor;

import org.tigris.apexam.Message;
import org.tigris.apexam.configuration.ConfigurationManager;
import org.tigris.apexam.implementation.SimpleMessage;

/**
 * @author zhisen.huang
 * 
 */
public class SimpleConfigurationManager implements ConfigurationManager {

	String fileName;

	Properties properties = null;

	ExpressionProcessor expressionProcessor = null;

	String messageName;

	Message message = null;

	public SimpleConfigurationManager(String fileName) {
		this.fileName = fileName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.tigris.apexam.ConfigurationManager#getMessages()
	 */
	public Map<String, Message> getMessages() throws Exception {
		properties = new Properties();
		FileInputStream file = new FileInputStream(fileName);
		properties.load(file);
		file.close();

		Map<String, Message> messages = new HashMap<String, Message>();

		for (Iterator iterator = properties.keySet().iterator(); iterator
				.hasNext();) {
			messageName = (String) iterator.next();
			message = new SimpleMessage(messageName, properties
					.getProperty(messageName));
			message.setExpressionProcessor(expressionProcessor);
			messages.put(messageName, message);
		}
		return messages;
	}

	public void setExpressionProcessor(ExpressionProcessor expressionProcessor) {
		this.expressionProcessor = expressionProcessor;
	}
}
